<?php
namespace app\user\controller;
use app\common\controller\IndexBase;
use app\common\model\WeixinUser;

class Sendmessage extends IndexBase
{
    //微信提醒
    public function weixin()
    {
        $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
        $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
        $list = model('customerRemind')->where("remind_time<='".$endToday."' and remind_time >='".$beginToday."' and status='0'")->select();
        //$num['web'] = $num['count'] = '0';
        $count = 0;
        foreach ($list as $r){
            $remindlog = model('customerRemindLog')->where(['uid' => $r['uid'],'rid' => $r['id'],'type' => 'wechat',])->find();
            if(!$remindlog and isset($r['jdata']['wechat']) and $r['jdata']['wechat']=='on'){
                //获取用户信息
                $user = model('user')->get($r['uid']);
                $frist = $user['realname']."，您好，今日你有以下需要处理：";
                $keyword1 = $r['remark'];
                $customer = model('customer')->get($r['cid']);
                $keyword2 = $customer['cname']." / ".$customer['mobile'];
                $keyword3 = $r['create_time'];
                $remark = "请您及时处理！";
                if($user['openid']){
                    WeixinUser::remind_plan($user['openid'],$frist, $keyword1, $keyword2, $keyword3, $remark, 'https://crm.dingshibao.com/user/customer/remind/type/1.html');
                    model('customerRemindLog')->insert([
                        'shop_id' => $r['shop_id'],
                        'uid' => $r['uid'],
                        'rid' => $r['id'],
                        'type' => 'wechat',
                        'create_time' => time(),
                    ]);
                    $count = $count + 1;
                }
            }
        }
        if($count > 0){
            WeixinUser::send_noice(date('Y-m-d h:i:s',time()),"成功发送".$count."条, ","微信提醒","感谢您的查看");
        }        
    }

}
